//
//  kqyTabBar.m
//  百思不得姐os1
//
//  Created by kqy on 8/1/16.
//  Copyright © 2016 kqy. All rights reserved.
//

#import "kqyTabBar.h"
@interface kqyTabBar ()
@property (nonatomic, weak) UIButton *publishBtn;
@end

@implementation kqyTabBar
- (UIButton *)publishBtn {
    if (_publishBtn == nil) {
    UIButton *publishBtn = [[UIButton alloc] init];
    NSString *imageName = @"tabBar_publish_icon";
    NSString *selectedImageName = @"tabBar_publish_click_icon";
    UIImage *image = [UIImage imageNamed:@"tabBar_publish_icon"];
    UIImage *selectedImage = [UIImage imageNamed:@"tabBar_publish_click_icon"];
    UIImage *originImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *originSelectImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [publishBtn setImage:originImage forState:UIControlStateNormal];
    [publishBtn setImage:originSelectImage forState:UIControlStateHighlighted];
    [publishBtn addTarget:self action:@selector(publishClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:publishBtn];
    _publishBtn = publishBtn;
    }
    return _publishBtn;
}
//
//
//
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat tabbarWeight = self.frame.size.width / 5;
    CGFloat tabbarHeight = self.frame.size.height;
    int flag = 0;
    for (UIView *subView in self.subviews) {
        if (subView.class != NSClassFromString(@"UITabBarButton")) {
            continue;
        }
        if (![@"UITabBarButton" isEqualToString:NSStringFromClass(subView.class)]) {
            continue;
        }
        if(flag == 2) {
                  ++ flag ;
        }
        subView.frame = CGRectMake(flag * tabbarWeight, 0, tabbarWeight, tabbarHeight);
        ++ flag;
    }
         self.publishBtn.frame = CGRectMake(self.frame.size.width * 0.4, 0, self.frame.size.width * 0.2, self.frame.size.height);
        _publishBtn.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);
}

- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
    }
    return self;
}
- (void) publishClick {
    NSLog(@"publish click");
}
@end
